<template>
  <PageWrapper dense>
    <BasicTable @register="register">
      <template #toolbar>
        <a-button type="primary" @click="handleNew">新增</a-button>
        <TableAction />
      </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              label: '编辑',
              onClick: handleEdit.bind(null, record),
            },
            {
              label: '商品管理',
              onClick: handleProductManager.bind(null, record),
            },
          ]"
        />
      </template>
    </BasicTable>
  </PageWrapper>
</template>
<script lang="ts">
  import { defineComponent, onActivated } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { getBasicColumns } from './activitydata';
  import { useGo } from '/@/hooks/web/usePage';
  import { PageWrapper } from '/@/components/Page';
  import { useRouter } from 'vue-router';
  import { getActivityList } from '/@/api/sys/activityList';

  export default defineComponent({
    name: 'DocumentActivity',
    components: { BasicTable, TableAction, PageWrapper },
    setup() {
      const go = useGo();
      const { currentRoute } = useRouter();
      const [register, { reload }] = useTable({
        title: '活动管理',
        api: getActivityList,
        searchInfo: { searchSource: 0 },
        columns: getBasicColumns(),
        useSearchForm: false,
        striped: false,
        showIndexColumn: false,
        canResize: false,
        bordered: true,
        beforeFetch(info) {
          if (info && info.hd_id) {
            info.hd_id = info.hd_id[info.hd_id.length - 1];
          }
          return info;
        },
        fetchSetting: {
          pageField: 'pageIndex',
          totalField: 'total',
          listField: 'items',
          sizeField: 'pageSize',
        },
        actionColumn: {
          width: 160,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
          fixed: undefined,
        },
        rowKey: 'hd_id',
      });
      onActivated(() => {
        const { hd_id } = currentRoute.value.query;
        if (hd_id) {
          reload();
        }
      });
      function handleNew() {
        go('/document/edit');
      }
      function handleEdit(record: Recordable) {
        go('/document/edit?hd_id=' + record.hd_id);
      }
      function handleProductManager(record: Recordable) {
        go('/document/productManager?hd_id=' + record.hd_id);
      }
      return {
        register,
        handleNew,
        handleEdit,
        handleProductManager,
      };
    },
  });
</script>
<style lang="less">
  .ant-select-tree-dropdown {
    max-width: 600px;
  }

  .ant-form-item-control-input-content #thirdCategorySysNo div:first-child {
    overflow: hidden;
  }
</style>
